def prost(n):
    n = int(n)
    k = 0
    for i in range(2, n // 2+1):
        if (n % i == 0):
            k = k+1
    if (k <= 0):
        return True
    else:
        return False
        
def numb_ep(w):
    numbers = {
        'zero': '0',
        'one': '1',
        'two': '2',
        'three': '3',
        'four': '4',
        'five': '5',
        'six': '6',
        'seven': '7',
        'eight': '8',
        'nine': '9'
        }
    answer = ''.join(numbers[n] for n in word)
    if len(answer) != 3:
        print('Wrong input')
        return
    
    elif 100 <= int(answer) <= 999:
        l_prost, up_prost = int(answer), int(answer)
        while not prost(l_prost):
            l_prost -= 1
        while not prost(up_prost):
            up_prost += 1
        if int(answer) - l_prost <= up_prost - int(answer):
            return l_prost
        else:
            return up_prost


word = input().split()
print(numb_ep(word))